/*Problem Id:1033  User Id:tq 
Memory:24K  Time:15MS
Language:C++  Result:Accepted

	author: TangQiao , Wind @ Beijing Normal University

	problem name: Tree Recovery
	
	source :  BNU Online Judge
	
	problem type: 图论 树
	
	problem description: 已知前序及中序遍历,求树的后序遍历.
	   　　　　　　　　　算法：中序遍历每次把串分成了两个子部分，而这两个子部分与
                        　先序遍历的后面的字符串同样对应被分成了两部分。
                        这样，可以对这两部分做同样的操作，即可最后分成一个字符。
                        因为可能存在深度为26的二叉树，所以不采用下标对应结点的父子关系的方法
                        来记录， 而采用指针指向左子树和右子树。 

	date : 2005.7.12 北师大校队个人练习赛4
	       2006.7.8 　重做了一遍 
	
*/
#include <stdio.h>
#include <string.h>
typedef struct 
{
    char value;
    int left, right;
}NOD;
NOD ans[30];    

char s1[30], s2[30];

int num ;

void di(int from1, int to1, int from2, int to2)
{
    int pos, i;
    char ch;
    ans[num].value = ch = s1[from1];
    
    // search the same char at s2
    for (i=from2; i<=to2; ++i)
        if (ch == s2[i])
                break;
    pos = i;
    
    // check the left subtree
    int from, to, nownod = num, len_left=0;
    from = from2;
    to = pos - 1;
    if (from <= to) // the left subtree exist
    {
        num ++;
        ans[nownod].left = num;
        di(from1+1, (from1+1) + (to-from), from, to);
        len_left = to - from + 1;
    }    
    else 
    {
        ans[nownod].left = 0;
    }    
    
    // check the right subtree
    from = pos + 1;
    to = to2;
    if (from <= to) // the right subtree exist
    {
        num ++;
        ans[nownod].right = num;
        di(from1+len_left+1, to1, from, to);
    }    
    else
    {
        ans[nownod].right = 0;
    }    
    
}    

void output(int pos)
{
    if (ans[pos].left != 0) output(ans[pos].left);
    if (ans[pos].right != 0) output(ans[pos].right);
    printf("%c", ans[pos].value);
}    
int main()
{
    int len;
    while (scanf("%s%s", s1, s2)!=EOF)
    {
        memset(ans, 0, sizeof(ans));
        len = strlen(s1);
        num = 1;
        di(0, len-1, 0, len-1);        
        output(1);
        printf("\n");
    }        
    return 0;    
}    

